﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Common;
using DotNet.Model;
using System.Text;
using System.Collections.Generic;
public partial class Admin_DotNetMain : basePage
{
    public string state = "";//初始化地图菜单
    public string index="";//初始化默认按钮
    PowerBll pBll = new PowerBll();
    v_powerInfoBll vBll = new v_powerInfoBll();
    public StringBuilder ChildrenMenu = new StringBuilder();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            #region 清除所有的缓存
            if (Request.QueryString["action"] != null)
            {
                if (Request.QueryString["action"].ToString().Trim() == "restartcache")
                {
                    CacheUtil.Clear();
                    Response.Write("1");
                    Response.End();
                }
                if (Request.QueryString["action"].Trim() == "logout")
                {
                    DotCookie.Delete("adminUser");
                    DotCookie.Delete("adminPwd");
                    JsUtil.LocationNewHref("mainlogin.aspx");
                }
           
            }
            #endregion
           
        }
    }

    public string bindDataMenu()
    {
        string[] powerId=vBll.GetPower(DotCookie.Read("adminUser")).Split('|');
        IList<string> menu = new List<string>();//排除重复
        IList<power> list = new List<power>();
        StringBuilder sb = new StringBuilder();
        int t = 0;
        #region 初始化头部菜单导航
            for (int i = 0; i < powerId.Length; i++)
            {
                power po = pBll.GetModel(Convert.ToInt32(powerId[i]));
                string demoInfo = po.Demoinfo;
                string demoName = po.DemoName;
                string demoPage = po.Powerpage;
                string powerName = po.Powername;
                list.Add(po);
                if (!menu.Contains(demoName.Trim()))
                {
                    if (t==0)
                    {
                        index = demoPage;
                        t++;
                    }
                    sb.AppendFormat(" <li><em><a href=\"#\" id=\"header_{0}\" onClick=\"changeMenu('{1}', '{2}');\">{3}</a></em></li>", demoName.Trim(), demoName.Trim(), demoPage.Trim(), demoInfo.Trim());
                    state += " '" + demoName + "',";
                    menu.Add(demoName);
                }
            }
            #endregion

        #region 初始化子菜单
            for (int j = 0; j < menu.Count; j++)
            {
                ChildrenMenu.AppendFormat("<ul id=\"menu_{0}\" style=\"display: none\">", menu[j]);
                foreach (power p in list)
                {
                    if (p.DemoName.Contains(menu[j]))
                    {

                        ChildrenMenu.AppendFormat("<li><a href=\"{0}\" target=\"main\">{1}</a></li>", p.Powerpage, p.Powername);
                    }
                }
                ChildrenMenu.Append("</ul>");
            }
            #endregion
        state = state.Substring(1, state.Length - 2);
        return sb.ToString(); ;
    }
}
